package com.topvision.myviewtest.mvp;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

import com.topvision.myviewtest.R;
import com.topvision.myviewtest.mvp.api.ApiServer;
import com.topvision.myviewtest.mvp.bean.WeatherBean;
import com.topvision.myviewtest.mvp.provider.RetrofitProvider;

import butterknife.BindView;
import butterknife.ButterKnife;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Author: lucy
 * Comment: //TODO
 * Date: 2017-12-11 10:16
 */

public class MainActivityNormal extends AppCompatActivity {

    private final String TAG = this.getClass().getSimpleName();

    @BindView(R.id.tv_mvp_study)
    TextView mTvMvpStudy;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mvp_study);
        ButterKnife.bind(this);

    }

    public void request(View view) {
        clickRequest("101010100");
    }

    private void clickRequest(String cityId) {
        ApiServer apiServer = RetrofitProvider.get().create(ApiServer.class);
        Call<WeatherBean> requestWeather = apiServer.requestWeather(cityId);
        requestWeather.enqueue(new Callback<WeatherBean>() {
            @Override
            public void onResponse(Call<WeatherBean> call, Response<WeatherBean> response) {
                //请求成功
                mTvMvpStudy.setText(response.body().getWeatherinfo().toString());
            }

            @Override
            public void onFailure(Call<WeatherBean> call, Throwable t) {
                //请求失败
                mTvMvpStudy.setText(t.toString());
            }
        });
    }


}
